import { defineStore} from 'pinia'
import wallet from "../views/wallet.vue";

export const useStore = defineStore('store', {
    state: () => {//定义需要共享的变量
        return {
            author:'小明', //定义全局变量
            user:{        //定义一个对象
                name:'xiaoming',
                sex:'F'
            },
            token:'',
            price:'',
            createTime:'',
            room:{
                id:0,
                name:'',
                type:0,
                rate:0.0,
                position:'',
                status:0,
                info:'',
                price:0.0,
                utime:''
            },
            wallet:{
                id:0,
                userId:0,
                money:0,
                totalMoney:0,
                ctime:'',
                utime:'',
            },
            userRoom:{
                availableType:0,
                days:0,
                restDays:0,
                startMonth:0,
                startDay:0,
                endMonth:0,
                endDay:0,
                hotelRoom:{
                    id:0,
                    name:'',
                    type:0,
                    rate:0.0,
                    position:'',
                    status:0,
                    info:'',
                    price:0.0,
                    utime:''
                },
            }
        }
    },
    //定义方法  设置state中的值 set方法
    actions: {
        setAuthor(author){ //定义函数 修饰变量的值
            this.author=author;
        },
        setUser(user){   // 定义设置的函数
            this.user = user;
        },
        setToken(token){
            this.token = token;
        },
        setRoom(room){
            this.room = room;
        },
        setWallet(wallet){
            this.wallet = wallet;
        },
        setUserRoom(userRoom) {
            this.userRoom = userRoom;
        },
        setOrder(price, createTime){
            this.price = price;
            this.createTime = createTime
        }
    },
    persist: {
        enabled: true // true 表示开启持久化保存
    }
})